//
//  YTAccountLeftDetailViewController.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/5/19.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTAccountLeftDetailViewController.h"
#import "YTAccountMoneyDetailViewCell.h"
#import "YTUserProfileServices.h"
#import "YTWithdrawRecordModel.h"
#import "YTMoneyDetailFilterView.h"
#import "YTPopupView.h"

@interface YTAccountLeftDetailViewController ()
@property (strong, nonatomic) NSMutableArray<YTWithdrawRecordModel *> *dataList;
@end

@implementation YTAccountLeftDetailViewController

- (void)initialize {
    self.emptyDataImage = @"public_norecord";
    self.emptyDataTips = @"暂无相关记录";
    self.tableView.tableFooterView = [UIView new];
    self.dataList = [NSMutableArray array];
}

- (void)bindViewModel {
    [self loadDataFromServerWithData:nil];
}

- (void)loadDataFromServerWithData:(NSDictionary *)data {
    [SVProgressHUD show];
    [[YTUserProfileServices withdrawRecordList:data] subscribeNext:^(NSDictionary *response) {
        [SVProgressHUD dismiss];
        NSDictionary *data = response[@"responseData"];
        self.dataList = [[NSArray yy_modelArrayWithClass:[YTWithdrawRecordModel class] json:data[@"financeList"]] mutableCopy];
        [self.tableView reloadData];
    } error:^(NSError *error) {
        [SVProgressHUD dismiss];
    }];
}

#pragma mark - 筛选

- (IBAction)filterAction:(UIBarButtonItem *)sender {
    YTMoneyDetailFilterView *filter = [[YTMoneyDetailFilterView alloc] initWithFrame:CGRectMake(0, 0, 260, kScreenHeight)];
    filter.backgroundColor = [UIColor whiteColor];
    YTPopupView *popView  = [YTPopupView popupWithContentView:filter];
    popView.showType = YTPopupShowTypeSlideInFromRight;
    popView.dismissType = YTPopupDismissTypeSlideOutToRight;
    [popView showWithLayout:YTPopupLayoutMake(YTPopupHorizontalLayoutRight, YTPopupVerticalLayoutCenter)];
    
    filter.resetAction = ^{
        [popView dismiss:YES];
    };
    
    filter.completeAction = ^(NSDictionary *data) {
        [popView dismiss:YES];
        [self loadDataFromServerWithData:data];
    };
}


#pragma mark - UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YTAccountMoneyDetailViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YTAccountMoneyDetail" forIndexPath:indexPath];
    cell.model = _dataList[indexPath.row];
    return cell;
}

@end
